package com.beiming.libra.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.beiming.libra.domain.UserRoleRelation;
import com.beiming.libra.domain.dto.requestdto.UserRoleRelationRequestDTO;
import com.beiming.libra.service.UserRoleRelationService;
/**
 * 
 * @author weibo
 *
 */
@Controller
@Slf4j
@RequestMapping(value = "/userRoleRelation")
public class UserRoleRelationController {

  private static final Logger LOGGER = LoggerFactory.getLogger(UserRoleRelationController.class);
  @Resource
  private UserRoleRelationService userRoleRelationService;

  /**
   * 更新和新增合并在一起 添加用户和角色的关系
   */
  @RequestMapping(value = "insertUserRoleRelation", method = RequestMethod.POST)
  @ResponseBody
  public void insertAndUpdateUserRoleRelation(
      @RequestBody @Valid UserRoleRelationRequestDTO userRoleRelationRequestDTO) {
    userRoleRelationService.insertUserRoleRelation(userRoleRelationRequestDTO);
  }

  /**
   * 删除用户和角色信息
   */
  @RequestMapping(value = "deleteUserRoleRelation", method = RequestMethod.POST)
  @ResponseBody
  public void deleteUserRoleRelation(
      @RequestBody UserRoleRelationRequestDTO userRoleRelationRequestDTO) {
    userRoleRelationService.deleteUserRoleRelation(userRoleRelationRequestDTO);
  }

  /**
   * 获取用户和角色信息
   */
  @RequestMapping(value = "getUserRoleRelation", method = RequestMethod.POST)
  @ResponseBody
  public List<UserRoleRelation> getUserRoleRelation(
      @RequestBody UserRoleRelationRequestDTO userRoleRelationRequestDTO) {
    return userRoleRelationService.getUserRoleRelation(userRoleRelationRequestDTO);
  }
}
